package com.egao.api.controller.orderB;


import com.egao.api.base.BaseApiController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageResult2;
import com.egao.common.system.entity.OperRecord;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.MaintainFee;
import com.egao.orderB.service.MaintainFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/maintainFee")
@RestController
@Api(value = "运费维护管理",tags = {"运费维护管理"})
public class ApiMaintainFeeController extends BaseApiController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private MaintainFeeService maintainFeeService;

    /**
     * 运费维护列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "运费维护列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "boxType:箱型\n" +
            "address:详细地址\n" +
            " \n" +
            "返回的内容\n" +
            "id:id\n" +
            "companyId:公司id\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "miles:公里数\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "commission:佣金\n" +
            "address:详细地址\n" +
            "dock:口岸\n" +
            "remark:备注\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JSONObject list(PageResult2<T> page, MaintainFee maintainFee, HttpServletRequest request)  throws Exception{
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "运费维护列表", "运费维护列表",
                request.getServletPath(), "POST", "ApiMaintainFeeController.list", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return maintainFeeService.list(page, maintainFee, getLoginUser(request));
    }

    /**
     * 添加运费报价
     */
    @PostMapping("/listAll")
    @ApiOperation(value = "运费维护列表",notes = "" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "boxType:箱型\n" +
            "address:详细地址\n" +
            "dock:口岸\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public List<MaintainFee> listAll(MaintainFee maintainFee, HttpServletRequest request)  throws Exception{
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "运费维护列表", "运费维护列表",
                request.getServletPath(), "POST", "ApiMaintainFeeController.list", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return maintainFeeService.list(maintainFee, getLoginUser(request));
    }


    /**
     * 添加运费维护
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加运费维护",notes = "" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "miles:公里数\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "commission:佣金\n" +
            "address:详细地址\n" +
            "dock:口岸\n" +
            "remark:备注\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JsonResult save(MaintainFee maintainFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "添加运费维护", "添加运费维护",
                request.getServletPath(), "POST", "ApiMaintainFeeController.save", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return maintainFeeService.save(maintainFee, getLoginUser(request));
    }


    /**
     * 运费维护修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "运费维护修改",notes = "" +
            "id 运费维护的id 必填\n" +
            "province:省\n" +
            "city:市\n" +
            "district:县区\n" +
            "town:镇\n" +
            "miles:公里数\n" +
            "boxType:箱型\n" +
            "price:价格\n" +
            "driverPrice:司机价格\n" +
            "commission:佣金\n" +
            "address:详细地址\n" +
            "dock:口岸\n" +
            "remark:备注\n"
            ,httpMethod = "POST")
    @ResponseBody
    public JsonResult update(MaintainFee maintainFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "运费维护修改", "运费维护修改",
                request.getServletPath(), "POST", "ApiMaintainFeeController.update", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return maintainFeeService.update(maintainFee, getLoginUser(request));
    }

    /**
     * 运费维护删除
     */
    @PostMapping("/remove")
    @ApiOperation(value = "运费维护删除",notes = "" +
            "id 运费维护的id 必填\n"
            ,httpMethod = "POST")
    @ResponseBody
    public JsonResult remove(MaintainFee maintainFee, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "运费维护删除", "运费维护删除",
                request.getServletPath(), "POST", "ApiMaintainFeeController.remove", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return maintainFeeService.remove(maintainFee, getLoginUser(request));
    }


}
